package blog.test;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class MyLogAspect {  // 切面

    @Pointcut("execution(public * blog.test.TestService.say())")
    public void say() {
    }

    @Around("say()")
    public Object pp(ProceedingJoinPoint pjp) {

        System.out.println("==========>开始前的逻辑。。。");

        Object ret = null;  // 调用被执行方法

        try {
            ret = pjp.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }

        System.out.println("==========>完成后的逻辑。。。");

        return ret;
    }


    //定义通知
/*    @Around("@annotation(MyPointCut)")
    public Object qq(ProceedingJoinPoint pjp) throws Throwable{
        try {
            System.out.println("==========>开始前的逻辑。。。");

            Object ret = pjp.proceed();  // 调用被执行方法

            System.out.println("==========>完成后的逻辑。。。");

            return ret;
        }catch (Exception e){
            log.error("异常信息",e);
            throw e;
        }
    }*/

}